package com.strategy.pattern.factory;

import com.strategy.pattern.strategy.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cc
 * @classname PromotionStrategyFactory
 * @description 工厂模式-促销策略工厂
 * @date 2022/3/27 21:03
 */
public class PromotionStrategyFactory {

    private static Map<String, PromotionStrategy> promotionStrategyMapap = new HashMap<>();

    static {
        promotionStrategyMapap.put(PromotionKey.COUPON, new CouponStrategy());
        promotionStrategyMapap.put(PromotionKey.CASHBACK, new CashbackStrategy());
        promotionStrategyMapap.put(PromotionKey.GROUPBUY, new GroupbuyStrategy());
    }

    private static final PromotionStrategy emptyStrategy = new EmptyStrategy();

    public static PromotionStrategy getPromotionStrategy(String promotionKey) {
        if (!promotionStrategyMapap.containsKey(promotionKey)) {
            return emptyStrategy;
        }
        return promotionStrategyMapap.get(promotionKey);
    }

    //接口不能实例化所以默认静态
    public interface PromotionKey {
        String COUPON = "coupon";
        String CASHBACK = "cashback";
        String GROUPBUY = "groupbuy";
    }

}
